﻿using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Data;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Web;

public partial class Controls_LoanRepayment : System.Web.UI.UserControl
{
    int mLoanID = 0;
    int mIterationID = 0;
   
    public int LoanID
    {
        set { mLoanID = value; }
    }

    public int IterationID
    {
        set { mIterationID = value; }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        refundDateCalendarExtender.Format = Constants.Constants.ISODateBackwardDotsFormat;

        if (!IsPostBack)
        {
                    
        }
    }
    
    protected void ClearPersonalDataForms()
    {
       // infoBoxTitleLabel.Text = string.Empty;

        refundDateTextBox.Text = string.Empty;       
        refundInputPaysTextBox.Text = string.Empty;
    }

    public void Show()
    {
        string appPath = Utils.GetApplicationPath(Request);
        ClearPersonalDataForms();
               
        
        this.programmaticModalPopup.Show();
    }
    
    protected void saveButton_Click(object sender, EventArgs e)
    {
        TextBox dateTextBox = (TextBox)this.FindControl("refundDateTextBox");
        DateTime payDate = Convert.ToDateTime(dateTextBox.Text);
        
        decimal inputValue = 0;
        TextBox inputTextBox = (TextBox)this.FindControl("refundInputPaysTextBox");
        decimal.TryParse(inputTextBox.Text.Replace('.', ','), out inputValue);
                 
            //bool result = Utils.ModuleCredits().AddNewRefund(loanValue, iteration, payDate
            //    , main, profit, penalty, currenty, commission, avansValue, 0, out newPayID);
        

        //bool resultFinishedTranche = Utils.ModuleCredits().UpdateFinishedTranche(loanValue, iteration);
        
        
        RefundsWindowEventsArg args = new RefundsWindowEventsArg(true);
        EntrySelected(this, args);
        
    }

    protected void cancelButton_Click(object sender, EventArgs e)
    {
        RefundsWindowEventsArg args = new RefundsWindowEventsArg(true);
        EntrySelected(this, args);
    }

    public class RefundsWindowEventsArg : EventArgs
    {
        private bool resultRefund;
        public bool ResultRefund
        {
            get { return resultRefund; }
        }

        public RefundsWindowEventsArg(bool result)
        {
            resultRefund = result;
        }
    }

    public event CustomItemEventHandler EntrySelected;
    public delegate void CustomItemEventHandler(object sender, Controls_LoanRepayment.RefundsWindowEventsArg e);
}